package uk.ljmu.qudexapps.swfspreadsheet.exception;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;
import org.springframework.web.servlet.support.RequestContextUtils;
/**
 * Extends SimpleMappingExceptionResolver to add custom information when a exception is thrown:
 * - locale, for localised messages
 * - exception for exception information
 * 
 * @author amg857
 *
 */
public class CustomMappingExceptionResolver extends SimpleMappingExceptionResolver {

	@Override
	protected ModelAndView getModelAndView(String viewName, Exception ex,
			HttpServletRequest request) {
		ModelAndView mov = new ModelAndView();
		mov.addObject("exception", ex);
		mov.addObject("locale", RequestContextUtils.getLocale(request));
		mov.setViewName(viewName);
		
		return mov;
	}

}
